Home Forums Logo Maker Arcade Scripts Music / SFX Images Articles Ad Networks Contact
Login Sign up

my first game pyman

Forum: Showcase

  • Posts 19
  • Views 275
  • Last Activity 1¬†month, 4¬†weeks ago
Posts: 37
Level: 8
HP: 1

jamtron

Posted 4th July 2017 - 7:26 PM

sup everyone!
just wanted ya to know that i found my first game that i made!
it's written in python ofc
i'll be pastin the code shortly


Posts: 37
Level: 8
HP: 1

jamtron

Posted 4th July 2017 - 7:27 PM

here is da code!!!
the game's called pyman bc it's a python version of hangman

from random import randrange

with open('words.txt','r') as f:
words = f.readlines()
for i in range(0,len(words)):
words[i] = words[i].split('\n')[0]
chances = 5
sc = 0
word = list(words[randrange(0,len(words))])
mask = list()
for char in word:
mask.append('_')
c = ''
while chances != 0 and sc != len(mask):
flag = False
print("Chances left %s " % str(chances))
print("Score %s " % str(sc))
print(mask)
c = ''
while len(c) < 1:
c = input('Input a letter: ')
c = c[0]
for ch in word:
if c == ch:
mask[word.index(ch)] = c
word[word.index(ch)] = '_'
sc = sc + 1
flag = True
if flag == False:
chances = chances - 1
print(mask)
print("Game done")


Posts: 37
Level: 8
HP: 1

jamtron

Posted 4th July 2017 - 7:29 PM

ik is not perfect but it was ma first game


Posts: 95
Level: 13
HP: 5

rudinski00

Posted 4th July 2017 - 7:32 PM

ik is not perfect but it was ma first game

Posted by jamtron at 4th July 2017 - 7:29 PM

Yeah, I can see the imperfections...
For example if I don't guess the word and lose all my chances, I'll never know what was the original word :)


Posts: 37
Level: 8
HP: 1

jamtron

Posted 9th July 2017 - 11:47 PM

Yeah, I can see the imperfections...
For example if I don't guess the word and lose all my chances, I'll never know what was the original word :)

Posted by rudinski00 at 4th July 2017 - 7:32 PM

ye ma man
i dunno if ill be fixin dis stuff tho
prob will but who knows


Posts: 33
Level: 8
HP: 6

Pacey

Posted 10th July 2017 - 8:25 PM

Hey man, congrats! Are you going to do anything with it or is it more of a test project?


Posts: 34
Level: 7
HP: 1

cppdev99

Posted 13th July 2017 - 9:13 AM

Hey that's great :D
I may wanna make a C++ version of it!


Posts: 37
Level: 8
HP: 1

jamtron

Posted 13th July 2017 - 9:14 AM

Hey man, congrats! Are you going to do anything with it or is it more of a test project?

Posted by Pacey at 10th July 2017 - 8:25 PM

ya it was a learning project but i may expand it a bit


Posts: 34
Level: 7
HP: 1

cppdev99

Posted 13th July 2017 - 10:03 AM


#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cstdlib>
#include <ctime>
#include <sstream>

int main()
{
srand(time(NULL));
std::vector<std::string> words;
int triesLeft = 5;
int lettersLeft = 0;
std::ifstream wFile("words.txt", std::ios::in);
for (std::string str; std::getline(wFile,str); )
{
words.push_back(str);
}
std::string out, orig;
orig = words[rand()%words.size()];
lettersLeft = orig.length();
for (size_t i = 0; i < lettersLeft; i++)
{
out += "_";
}
wFile.close();
while (triesLeft != 0 && lettersLeft != 0)
{
bool flagged = false;
std::cout << "Tries left: " << triesLeft << std::endl;
std::cout << out << std::endl;
char letter = '1';
do
std::cin >> letter;
while (!isalpha(letter));
for (size_t i = 0; i < orig.length(); i++)
{
if (orig[i] == letter)
{
lettersLeft--;
orig[i] = orig[i] - '0';
out[i] = letter;
flagged = true;
}
}
if (!flagged)
triesLeft--;
}
for (size_t i = 0; i < orig.length(); i++)
{
if (!isalpha(orig[i]))
orig[i] = orig[i] + '0';
}
if (lettersLeft == 0)
std::cout << "You won!\n";
else
std::cout << "You lost!\nThe word was: " << orig << std::endl;
system("pause > NUL");
return 0;
}


Posts: 95
Level: 13
HP: 5

rudinski00

Posted 15th July 2017 - 3:27 PM


#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cstdlib>
#include <ctime>
#include <sstream>

int main()
{
srand(time(NULL));
std::vector<std::string> words;
int triesLeft = 5;
int lettersLeft = 0;
std::ifstream wFile("words.txt", std::ios::in);
for (std::string str; std::getline(wFile,str); )
{
words.push_back(str);
}
std::string out, orig;
orig = words[rand()%words.size()];
lettersLeft = orig.length();
for (size_t i = 0; i < lettersLeft; i++)
{
out += "_";
}
wFile.close();
while (triesLeft != 0 && lettersLeft != 0)
{
bool flagged = false;
std::cout << "Tries left: " << triesLeft << std::endl;
std::cout << out << std::endl;
char letter = '1';
do
std::cin >> letter;
while (!isalpha(letter));
for (size_t i = 0; i < orig.length(); i++)
{
if (orig[i] == letter)
{
lettersLeft--;
orig[i] = orig[i] - '0';
out[i] = letter;
flagged = true;
}
}
if (!flagged)
triesLeft--;
}
for (size_t i = 0; i < orig.length(); i++)
{
if (!isalpha(orig[i]))
orig[i] = orig[i] + '0';
}
if (lettersLeft == 0)
std::cout << "You won!\n";
else
std::cout << "You lost!\nThe word was: " << orig << std::endl;
system("pause > NUL");
return 0;
}

Posted by cppdev99 at 13th July 2017 - 10:03 AM

Hey, nice way to do everything with 2 strings, probably could be more optimized ;)
Try it :)
I'm sure you can


You must be logged in to post a response to this thread.

Login