Results 1 to 8 of 8
  1. #1
    deanugbu's Avatar
    Join Date
    Jan 2016
    Gender
    male
    Posts
    38
    Reputation
    10
    Thanks
    1

    help me with coding

    i am really bad at coding i dont know anything and my assignment is due next week could someone do this or help thanks in advance
    any help in ethier of the games/tasks would be helpful
    also its in visual studio
    Attached Thumbnails Attached Thumbnails
    ppppppppppp.PNG  

    ppppppppppp2.PNG  

    Last edited by deanugbu; 02-27-2017 at 08:36 PM.

  2. #2
    Cinodor's Avatar
    Join Date
    Mar 2012
    Gender
    male
    Location
    10.903486, 19.93219
    Posts
    714
    Reputation
    225
    Thanks
    159
    My Mood
    Relaxed
    Can't see the attachments, what are you currently learning in your C# class? I may be able to help you. Let me know! You could also try SO, but they are full of angry people who will flame if you ask a question in a dumb way.

  3. #3
    deanugbu's Avatar
    Join Date
    Jan 2016
    Gender
    male
    Posts
    38
    Reputation
    10
    Thanks
    1
    thanks we are learning to make a nots and crosses gaming using console.write,readline,readkey, the attachments display the task i have to finish i would be grateful for any help given!

  4. #4
    PurpleOldMaN's Avatar
    Join Date
    Jul 2014
    Gender
    male
    Location
    Giveaway section
    Posts
    828
    Reputation
    22
    Thanks
    60
    Wow I wish my school did this, this shit looks so fun

    - - - Updated - - -

    I mean I could easily do this in c++ but I'm just now getting into c# sorry lol
    bananas float in water

  5. #5
    deanugbu's Avatar
    Join Date
    Jan 2016
    Gender
    male
    Posts
    38
    Reputation
    10
    Thanks
    1
    its alright

  6. #6
    Biesi's Avatar
    Join Date
    Dec 2011
    Gender
    male
    Posts
    4,993
    Reputation
    374
    Thanks
    8,808
    My Mood
    Twisted

    I recommend you to not just copy and paste this since I don't know the exact output the task wanted. Also I don't know if the lecturer will ask you about certain code-style and flow decisions I made.

     
    Code:
    namespace Nac
    {
        using System;
        using System.Collections.Generic;
    
        internal static class Program
        {
            private class Position
            {
                public int X { get; private set; }
    
                public int Y { get; private set; }
    
                public Position(int x, int y)
                {
                    this.X = x;
                    this.Y = y;
                }
    
                public void Right()
                {
                    this.Y++;
                }
    
                public void Left()
                {
                    this.Y--;
                }
    
                public void Up()
                {
                    this.X--;
                }
    
                public void Down()
                {
                    this.X++;
                }
            }
    
            private const int Height = 3;
            private const int Width = 3;
    
            private const char Blank = ' ';
            private const char HumanPlayerSymbol = 'X';
            private const char AiPlayerSymbol = 'O';
    
            private static readonly Random Random = new Random();
            private static Position _cursorPosition = new Position(0, 0);
            private static readonly char[,] Field = new char[Program.Height, Program.Width];
    
            private static void Main()
            {
                Console.Title = "Tic-tac-toe";
                Console.CursorVisible = false;
    
                do
                {
                    Program.ResetField();
                    while (Program.HandleInput())
                    {
                        Program.Render();
                    }
                } while (Console.ReadKey(false).Key == ConsoleKey.R);
            }
    
            private static void ResetField()
            {
                for (int x = 0; x < Program.Height; x++)
                {
                    for (int y = 0; y < Program.Width; y++)
                    {
                        Program.Field[x, y] = Program.Blank;
                    }
                }
    
                Program.Render();
            }
    
            private static bool HandleInput()
            {
                switch (Console.ReadKey(true).Key)
                {
                    case ConsoleKey.Escape:
                    case ConsoleKey.Q:
                        return false;
    
                    case ConsoleKey.RightArrow:
                        if (Program._cursorPosition.Y < Program.Width - 1)
                        {
                            Program._cursorPosition.Right();
                        }
    
                        break;
    
                    case ConsoleKey.LeftArrow:
                        if (Program._cursorPosition.Y > 0)
                        {
                            Program._cursorPosition.Left();
                        }
    
                        break;
    
                    case ConsoleKey.DownArrow:
                        if (Program._cursorPosition.X < Program.Height - 1)
                        {
                            Program._cursorPosition.Down();
                        }
    
                        break;
    
                    case ConsoleKey.UpArrow:
                        if (Program._cursorPosition.X > 0)
                        {
                            Program._cursorPosition.Up();
                        }
    
                        break;
    
                    case ConsoleKey.Spacebar:
                        if (Program.SetCell(Program._cursorPosition.X, Program._cursorPosition.Y, Program.HumanPlayerSymbol) == false)
                        {
                            break;
                        }
    
                        if (Program.PrintWinner())
                        {
                            return false;
                        }
    
                        if (Program.MakeAiMove() == false)
                        {
                            Program.PrintMessage("Uh oh.. nobody wins. Press 'R' to play again.", ConsoleColor.Red);
                            return false;
                        }
    
                        if (Program.PrintWinner())
                        {
                            return false;
                        }
                        
                        break;
    
                    case ConsoleKey.R:
                        Program.ResetField();
                        break;
                }
    
                return true;
            }
    
            private static bool PrintWinner()
            {
                char winner = Program.DetermineWinner();
                if (winner != Program.Blank)
                {
                    Program.Render();
                    Program.PrintMessage($"Player {winner} won. Press 'R' to play again.", ConsoleColor.Green);
                    return true;
                }
    
                return false;
            }
    
            private static void PrintMessage(string message, ConsoleColor color)
            {
                Console.ForegroundColor = color;
                Console.SetCursorPosition(0, Program.Height * 2);
                Console.WriteLine(message);
                Console.ResetColor();
    
                Program.RenderCursor();
            }
    
            private static IList<Position> GetAvailableCells()
            {
                List<Position> available = new List<Position>();
                for (int x = 0; x < Program.Height; x++)
                {
                    for (int y = 0; y < Program.Width; y++)
                    {
                        if (Program.Field[x, y] == Program.Blank)
                        {
                            available.Add(new Position(x, y));
                        }
                    }
                }
    
                return available;
            }
    
            private static char DetermineWinner()
            {
                // Horizontally
                for (int x = 0; x < Program.Height; x++)
                {
                    bool won = true;
                    for (int y = 0; y < Program.Width - 1; y++)
                    {
                        won = won && Program.Field[x, y] != Program.Blank && Program.Field[x, y] == Program.Field[x, y + 1];
                    }
    
                    if (won)
                    {
                        return Program.Field[x, 0];
                    }
                }
    
                // Vertically
                for (int y = 0; y < Program.Width; y++)
                {
                    bool won = true;
                    for (int x = 0; x < Program.Height - 1; x++)
                    {
                        won = won && Program.Field[x, y] != Program.Blank && Program.Field[x, y] == Program.Field[x + 1, y];
                    }
    
                    if (won)
                    {
                        return Program.Field[0, y];
                    }
                }
    
                // Diagonal left to right
                {
                    bool won = true;
                    for (int i = 0; i < Program.Height - 1; i++)
                    {
                        won = won && Program.Field[i, i] != Program.Blank &&
                              Program.Field[i, i] == Program.Field[i + 1, i + 1];
                    }
    
                    if (won)
                    {
                        return Program.Field[0, 0];
                    }
                }
    
                // Diagonal right to left
                {
                    bool won = true;
                    for (int i = 0; i < Program.Height - 1; i++)
                    {
                        won = won && Program.Field[i, Program.Width - i - 1] != Program.Blank &&
                              Program.Field[i, Program.Width - i - 1] == Program.Field[i + 1, Program.Width - i - 2];
                    }
    
                    if (won)
                    {
                        return Program.Field[0, Program.Width - 1];
                    }
                }
    
                return Program.Blank;
            }
    
            private static bool MakeAiMove()
            {
                IList<Position> availableCells = Program.GetAvailableCells();
                if (availableCells.Count == 0)
                {
                    return false;
                }
    
                int pick = Program.Random.Next(0, availableCells.Count);
                Program.SetCell(availableCells[pick].X, availableCells[pick].Y, Program.AiPlayerSymbol);
                return true;
            }
    
            private static bool SetCell(int x, int y, char symbol)
            {
                if (Program.Field[x, y] != Program.Blank)
                {
                    return false;
                }
    
                if (x > Program.Height || x < 0 || y > Program.Width || y < 0)
                {
                    return false;
                }
    
                Program.Field[x, y] = symbol;
                return true;
            }
    
            private static void Render()
            {
                Console.SetCursorPosition(0, 0);
    
                for (int x = 0; x < Program.Height; x++)
                {
                    for (int y = 0; y < Program.Width - 1; y++)
                    {
                        Console.Write($" {Program.Field[x, y]} |");
                    }
    
                    Console.Write($" {Program.Field[x, Program.Width - 1]} ");
                    Console.WriteLine();
    
                    if (x != Program.Height - 1)
                    {
                        const int numberOfDashes = (Program.Width - 1) * 4 + 3;
                        Console.WriteLine(new string('-', numberOfDashes));
                    }
                }
    
                // Clear printed message
                Console.WriteLine();
                Console.WriteLine(new string('\0', Console.BufferWidth));
    
                Program.RenderCursor();
            }
    
            private static void RenderCursor()
            {
                Console.SetCursorPosition(Program._cursorPosition.Y * 4 + 1, Program._cursorPosition.X * 2);
    
                Console.BackgroundColor = ConsoleColor.Cyan;
                Console.ForegroundColor = ConsoleColor.Black;
                Console.Write(Program.Field[Program._cursorPosition.X, Program._cursorPosition.Y]);
                Console.ResetColor();
            }
        }
    }


     


     



    Use the arrow keys to navigate within the grid, spacebar to set the cell to 'X' and R to reset the game.

     
    Code:
    namespace Golf
    {
        using System;
        using System.Collections.Generic;
    
        internal static class Program
        {
            private class GolfClub
            {
                public string Name { get; private set; }
    
                public int MinDistance { get; private set; }
    
                public int MaxDistance { get; private set; }
    
                public GolfClub(string name, int min, int max)
                {
                    this.Name = name;
                    this.MinDistance = min;
                    this.MaxDistance = max;
                }
    
                public int Hit(int distanceToHole)
                {
                    if (distanceToHole <= this.MaxDistance && distanceToHole >= this.MinDistance)
                    {
                        return Program.Random.Next(this.MinDistance, distanceToHole);
                    }
    
                    return Program.Random.Next(this.MinDistance, this.MaxDistance + 1);
                }
            }
    
            private static readonly Random Random = new Random();
            private static int _remainingDistance;
            private static GolfClub _selectedClub;
            private static int _hits;
    
            private static readonly List<GolfClub> Clubs = new List<GolfClub>
            {
                new GolfClub("Wood", 150, 500),
                new GolfClub("Iron", 100, 300),
                new GolfClub("Putter", 1, 50)
            };
    
            private static void Main()
            {
                Console.Title = "Golf";
                Console.CursorVisible = false;
                
                do
                {
                    Program.Reset();
                    while (Program._remainingDistance != 0)
                    {
                        Console.Clear();
    
                        Program.PrintFieldInfo();
                        Program.PrintClubInfos();
                        Program.SelectClub();
    
                        Program.PerformHit();
                    }
    
                    Console.Clear();
                    Console.WriteLine($"Took you {Program._hits} damn hits.");
    
                } while (Console.ReadKey(true).Key == ConsoleKey.R);
            }
    
            private static void PrintClubInfos()
            {
                for (int i = 0; i < Program.Clubs.Count; i++)
                {
                    Console.WriteLine($"{i + 1}) {Program.Clubs[i].Name}");
                    Console.WriteLine($"   Distance: {Program.Clubs[i].MinDistance}m - {Program.Clubs[i].MaxDistance}m");
                    Console.WriteLine();
                }
            }
    
            private static void PrintFieldInfo()
            {
                Console.WriteLine($"Distance to hole: {Program._remainingDistance}m");
                Console.WriteLine($"Tries: {Program._hits}");
                Console.WriteLine();
            }
    
            private static int ConsoleKeyToInt()
            {
                ConsoleKeyInfo key;
                do
                {
                    key = Console.ReadKey(true);
                } while (key.Key > ConsoleKey.D9 || key.Key < ConsoleKey.D0);
    
                return (int)key.Key - (int)ConsoleKey.D0;
            }
    
            private static void SelectClub()
            {
                Console.WriteLine("Please select your club.");
                Console.WriteLine();
    
                int selection = Program.ConsoleKeyToInt();
                Program._selectedClub = Program.Clubs[selection - 1];
            }
    
            private static void PerformHit()
            {
                int distance = Program._selectedClub.Hit(Program._remainingDistance);
                Program._remainingDistance -= distance;
                if (Program._remainingDistance < 0)
                {
                    Program._remainingDistance *= -1;
                }
    
                Program._hits++;
            }
    
            private static void Reset()
            {
                Program._remainingDistance = Program.Random.Next(300, 500);
                Program._hits = 0;
                Program._selectedClub = Program.Clubs[0];
            }
        }
    }


     


    Press 1-3 to select a club for the next hit. When the game has finished press R for another round. I didn't spend much time trying to create a decent calculation tho.

    Last edited by Biesi; 03-03-2017 at 04:53 AM.

  7. The Following 2 Users Say Thank You to Biesi For This Useful Post:

    Luverdark (03-05-2017),Zenitram (05-23-2017)

  8. #7
    Luverdark's Avatar
    Join Date
    Jul 2015
    Gender
    male
    Location
    7,821
    Posts
    4,986
    Reputation
    1386
    Thanks
    2,030
    My Mood
    Yeehaw
    There's a dude in the marketplace that'll help ya for some small cash




     
    Member Since 07-18-2015
    Mpgh Premium 07-17-2016
    Mpgh Premium Seller 08-17-2016
    Mpgh News Force (Gaming News) 02-09-2017
    Mpgh News Resignation 06-08-2017
    Realm Of The Mad God Minion 12-11-2017
    Former Staff 09-25-2018

  9. #8
    supermarre1's Avatar
    Join Date
    Oct 2015
    Gender
    male
    Posts
    72
    Reputation
    44
    Thanks
    175
    My Mood
    Cool
    This app helped me really much! It's 100% free, but I THINK only on android.
    https://play.google.com/store/apps/d...lolearn.csharp
    500 000 downloads with a rating of 4.8 out of 5.
    It's more like a quiz with description. Great interface and a growing community, they also have a free IDE which you can create your own console application through your phone though you cannot install your own made app, but you can run it on their servers.
    Good luck!
    -Supermarre1
    Last edited by supermarre1; 05-17-2017 at 04:45 PM.

Similar Threads

  1. Replies: 8
    Last Post: 12-05-2017, 09:17 AM
  2. [Help Request] Can anyone help me with code something
    By muddiswag321 in forum Garry's Mod Discussions & Help
    Replies: 4
    Last Post: 07-20-2015, 12:43 AM
  3. [Solved] Help me with codes please.
    By raenraphael in forum CrossFire Help
    Replies: 2
    Last Post: 05-24-2012, 07:55 PM
  4. [Help Request] Easy Help with coding hacks? like the easiest hacks?
    By 0pticisback in forum Combat Arms EU Help
    Replies: 5
    Last Post: 12-22-2011, 05:19 AM
  5. [Help]problem with code[/solved]
    By pushdis15 in forum Visual Basic Programming
    Replies: 2
    Last Post: 04-08-2011, 06:41 AM